<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    private $_callback;
    public function jiami($data){
        $jm = new \Home\Service\Aes2();
        $data = json_encode($data,JSON_UNESCAPED_SLASHES);
        $data = $jm->encrypt($data);
        return $data;
    }
    public function jiemi($data){
        $jm = new \Home\Service\Aes2();
        $data = $jm->decrypt($data);
        $data = json_decode($data,true);
        return $data;
    }

    public function _initialize(){
        header('content-type:text/json;charset=utf-8');
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        header('Access-Control-Allow-Methods: GET, POST, PUT');

        // print_r('111');die;
        if(!empty(I('vid'))){
//            echo json_encode(['ret' => '1002','code'=>'系统维护中，维护时间至11：30结束']);
//            exit();
            $is_lock = D('Userlogin')->where(array('vid'=>I('vid')))->getField('is_lock');
            if($is_lock=='1'){
                echo json_encode(['ret'=>'1002','code'=>'您的账号存在异常，请联系客服']);die;
            }
        }
        // foreach ($_GET as $key => $value) {
        //     $_GET[$key] = decrypt($value);
        // }
        // foreach ($_POST as $key => $value) {
        //     $_POST[$key] = decrypt($value);
        // }
        //
        // print_r($_POST);die;
        // print_r($_GET);die;

        // $getCallback  = I('get.callback','');
        // $postCallback = I('post.callback','');
        // if(!empty($getCallback)){
        //     $this->_callback = $getCallback;
        // }
        //  if(!empty($postCallback)){
        //      $this->_callback = $postCallback;
        // }
    }
    //后置操作方法
    public function __destruct(){
        if(!empty($this->_callback)){
           $this->return['callback'] = $this->_callback;
        }
        if(empty($this->return)){
            return true;
        }
        echo json_encode($this->return);
        // echo encrypt(json_encode($this->return));
        // print_r($this->return);
        return true;
    }
}